package com.my.bootvue.controller;


import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author peanut
 */
@Controller
public class UserLoginController {


    @PostMapping("/user/login")
    public String login(@RequestParam ("userName")String userName,
                        @RequestParam ("password")String password ,HttpServletRequest request) {
        if ("admin".equals(userName) && "123456".equals(password)) {
            // 之所以这样redirect   是因为防止重复提交
            request.getSession().setAttribute("userName" , userName);
            request.getSession().setAttribute("password" , password);
            return "redirect:/main";
        } else {
            return "index";
        }
    }
}
